import API from "../../api/index";
Page({
  data: {
    selected: 1,
    color: "#999999",
    selectedColor: "#F45F04",
    list: [{
      iconPath: "/static/image/icon/icon_application.png",
      selectedIconPath: "/static/image/icon/icon_application_hover.png",
      text: "新申请",
      count: 0
    }, {
      iconPath: "/static/image/icon/icon_approve.png",
      selectedIconPath: "/static/image/icon/icon_approve_hover.png",
      text: "我的审批",
      count: 0
    },
    {
      iconPath: "/static/image/icon/icon_submitted.png",
      selectedIconPath: "/static/image/icon/icon_submitted_hover.png",
      text: "提交记录",
      count: 0
    }]
  },
  switchTab(e) {
    const data = e.currentTarget.dataset
    this.setData({
      selected: data.index
    })
    if(this.data.selected==1){
      this.approve = this.selectComponent("#approve");
    }else if(this.data.selected==2){
      this.commitRecord = this.selectComponent("#commitRecord");
    }
  },
  onReady:function(){
    this.approve = this.selectComponent("#approve");
  },
  onPullDownRefresh() {
    if(this.data.selected==1){
      this.approve.data.start=0
      this.approve._getExamineList();
    }else if(this.data.selected==2){
      this.commitRecord.data.start=0
      this.commitRecord.__getRecordList();
    }
    
    setTimeout(function(){
      wx.stopPullDownRefresh()
    },1000)
  },
  onShow(){
    this._getunfinish()
    this.onPullDownRefresh()
  },
  _getunfinish(){
    // job_num	今天未完成任务数量
    // deal_num	审批待处理
    // feedback_num	记录反馈
    // my_num	我的
    API.getunfinish().then(res=>{
        this.setData({
          ['list[1].count']: res.data.deal_num,
          ['list[2].count']: res.data.feedback_num
        })
    })
  },
  onReachBottom() {
    if(this.data.selected==1){
      this.approve.data.start=this.approve.data.list.length
      this.approve._getExamineList();
    }else if(this.data.selected==2){
      this.commitRecord.data.start=this.commitRecord.data.list.length
      this.commitRecord.__getRecordList();
    }
  },
})